﻿using System;
using System.Diagnostics;

namespace PoolKit
{
    internal class StopwatchAdapted : IStopwatch
    {
        private readonly Stopwatch _stopwatch;

        public StopwatchAdapted(Stopwatch stopwatch)
        {
            if (stopwatch == null) throw new ArgumentNullException("stopwatch");

            _stopwatch = stopwatch;
        }

        /// <summary>
        /// Starts, or resumes, measuring elapsed time for an interval.
        /// </summary>
        /// <filterpriority>1</filterpriority>
        public void Start()
        {
            _stopwatch.Start();
        }

        /// <summary>
        /// Stops measuring elapsed time for an interval.
        /// </summary>
        /// <filterpriority>1</filterpriority>
        public void Stop()
        {
            _stopwatch.Stop();
        }

        /// <summary>
        /// Gets the total elapsed time measured by the current instance.
        /// </summary>
        /// <returns>
        /// A read-only <see cref="T:System.TimeSpan"/> representing the total elapsed time measured by the current instance.
        /// </returns>
        /// <filterpriority>1</filterpriority>
        public TimeSpan Elapsed
        {
            get { return _stopwatch.Elapsed; }
        }
    }
}